package src

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"math/rand"
	"time"
)

func CreateCaptcha() string {
	return fmt.Sprintf("%011v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
}
//比特转字符串
func ByteToString(origin *gin.Context) string{
	buf := make([]byte, 2024);//定义一个切片
	n, _ := origin.Request.Body.Read(buf);
	str := string(buf[0:n]);//把传送过来的数据转化成了字符串
	return str
}
//返回数据的类型
func Typeof(v interface{}) string {
	return fmt.Sprintf("%T", v)
}
//获取随机字符串
func GetRandomString(length int) string {
	str := "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
	var (
		result []byte
		b      []byte
		r      *rand.Rand
	)
	b = []byte(str)
	r = rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := 0; i < length; i++ {
		result = append(result, b[r.Intn(len(b))])
	}
	return string(result)
}